package application;
	
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ToolBar;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class Main extends Application {
	
	private AnchorPane centerAP;
	public Parent createContent() {
        BorderPane borderPane = new BorderPane();

       //Top content
       ToolBar toolbar = new ToolBar();
       Button homeBtn=new Button("Home");
       homeBtn.setOnAction(new EventHandler<ActionEvent>() {
		
		@Override
		public void handle(ActionEvent event) {
			// TODO Auto-generated method stub
			if(centerAP!=null && centerAP.isVisible()) {
				centerAP.setVisible(false);
			}else if(centerAP!=null && !centerAP.isVisible()){
				centerAP.setVisible(true);
			}
		}
	});
       
       toolbar.getItems().add(homeBtn);
       toolbar.getItems().add(new Button("Options"));
       toolbar.getItems().add(new Button("Help"));
       toolbar.setBackground(new Background(new BackgroundFill(Color.RED,null,null)));
       borderPane.setTop(toolbar);

       //Left content
       Label label1 = new Label("Left hand");
       Button leftButton = new Button("left");
       VBox leftVbox = new VBox();
       leftVbox.getChildren().addAll(label1, leftButton);
       leftVbox.setBackground(new Background(new BackgroundFill(Color.AQUA,null,null)));
       borderPane.setLeft(leftVbox);

       //Right content
       Label rightlabel1 = new Label("Right hand");
       Button rightButton = new Button("right");

       VBox rightVbox = new VBox();
       rightVbox.getChildren().addAll(rightlabel1, rightButton);
       rightVbox.setBackground(new Background(new BackgroundFill(Color.GREEN,null,null)));
       borderPane.setRight(rightVbox);

       //Center content
       Label centerLabel = new Label("Center area.");
       centerLabel.setWrapText(true);
       String IMAGE = "icon-48x48.png";
       Image ICON_48 = new Image(getClass().getResourceAsStream(IMAGE));
       ImageView imageView = new ImageView(ICON_48);

       //Using AnchorPane only to position items in the center
        centerAP = new AnchorPane();
       AnchorPane.setTopAnchor(centerLabel, Double.valueOf(5));
       AnchorPane.setLeftAnchor(centerLabel, Double.valueOf(20));
       AnchorPane.setTopAnchor(imageView, Double.valueOf(40));
       AnchorPane.setLeftAnchor(imageView, Double.valueOf(30));
       centerAP.getChildren().addAll(centerLabel, imageView);
       centerAP.setBackground(new Background(new BackgroundFill(Color.GOLD,null,null)));
       borderPane.setCenter(centerAP);

       //Bottom content
       Label bottomLabel = new Label("At the bottom.");
       borderPane.setBottom(bottomLabel);
       bottomLabel.setBackground(new Background(new BackgroundFill(Color.GRAY,null,null)));
       borderPane.setPrefSize(1024, 768);
       return borderPane;
   }

   @Override
   public void start(Stage primaryStage) throws Exception {
	   primaryStage.setTitle("BorderPane");
       primaryStage.setScene(new Scene(createContent()));
       primaryStage.show();
   }

   /**
    * Java main for when running without JavaFX launcher
    */
   public static void main(String[] args) {
       launch(args);
   }
}
